package gui;

/**
 * @author Ramy Refky 
 * */
public class CustomComponentGraphics extends ComponentGraphics{

	private static final long serialVersionUID = 1L;
	
	int clockPin;
	boolean showDetails;
	
	/**
	 * Constructor initializes CUSTOM Gate by initializing ComponentGraphics, and then painting the CustomComponentLabel.
	 * @param MainGui, XLocation, YLocation, Width, Height, NumberOfInputs, NumberOfOutputs, Title, ClockPin, ShowDetails
	 * */
	public CustomComponentGraphics(MainGui mg,int originalXLoc,int originalYLoc,
			int originalWidth,int originalHeight,int numOfInputs,int numOfOutputs,
			String text, int clockPin,boolean showDetails){
		
		super(mg,originalXLoc,originalYLoc,originalWidth,originalHeight,numOfInputs,numOfOutputs);
		
		this.clockPin=clockPin;
		this.showDetails=showDetails;
		
		int clockHeight=0;
		if(clockPin>0 && clockPin<=getInputPins().size()){
			clockHeight = getInputPins().get(clockPin-1).getY();
		}
		
		this.remove(compLabel);
		compLabel=new CustomComponentLabel(newXLoc,newYLoc,originalWidth,originalHeight);
		((CustomComponentLabel) compLabel).setComponentText(text);
		if(showDetails){
			((CustomComponentLabel) compLabel).setSpecsText(numOfInputs+"x"+numOfOutputs);
		}
		((CustomComponentLabel) compLabel).drawClockAtHeight(clockHeight);
		this.add(compLabel);
		setComponentZOrder(compLabel,0);
		repaint();
	}
	@Override
	public void zoomAdjust(Double zoomFactor){
		newWidth=(int) (originalWidth*zoomFactor);
		newHeight=(int) (originalHeight*zoomFactor);
		newXLoc=(int) (originalXLoc*zoomFactor);
		newYLoc=(int) (originalYLoc*zoomFactor);
		setBounds(newXLoc,newYLoc,newWidth,newHeight);
		compLabel.zoomAdjust(zoomFactor);
		adjustPins();
		
		int clockHeight=0;
		if(clockPin>0 && clockPin<=getInputPins().size()){
			clockHeight = getInputPins().get(clockPin-1).getY();
		}
		((CustomComponentLabel) compLabel).drawClockAtHeight(clockHeight);
		
		repaint();
	}
	/**
	 * Gets the title of the CUSTOM Gate.
	 * @return String
	 * */
	public String getComponentText(){
		return ((CustomComponentLabel) compLabel).getComponentText();
	}
	/**
	 * Gets the CUSTOM Gate's ComponentPin number that is set as a clock input.
	 * @return int
	 * */
	public int getClockPin(){
		return clockPin;
	}
	/**
	 * Gets the boolean value that toggles between displaying or hiding details of the CUSTOM Gate.
	 * @return boolean
	 * */
	public boolean getShowDetailsValue(){
		return showDetails;
	}
}